package xuecheng.tool.mq.redis;

import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

import lombok.extern.slf4j.Slf4j;
import xuecheng.tool.nosql.redis.CpxRedisAutoConfig;
import xuecheng.tool.nosql.redis.RedisUtils;

/**
 * 自定义 RedisMq 配置
 *
 * // @AutoConfigureOrder 默认为 0,
 *
 * // @AutoConfigureAfter(RedisAutoConfig.class) 保证 redis 配置完成之后才进行此项配置
 *
 * @author PengXueCheng
 * @version 1.0.0
 */
@SpringBootConfiguration
@AutoConfigureAfter(CpxRedisAutoConfig.class)
@EnableConfigurationProperties(RedisMqProperties.class)
// @ConditionalOnProperty(prefix = "cpx.redismq", value = "enable", havingValue = "true")
// @ConditionalOnBean(value = RedisUtils.class)
@Slf4j
public class CpxRedisMqAutoConfig implements BeanPostProcessor {

    /**
     * 注册生产者
     *
     * @param redisUtils
     * @return
     */
    @Bean
    public RedisMqUtils redisMqUtils(RedisUtils redisUtils) {
        return new RedisMqUtils(redisUtils);
    }

    /**
     * 消息订阅工厂
     *
     * @return
     */
    @Bean
    public ConsumerFactory subscribeTask(RedisUtils redisUtils, RedisMqUtils redisMqUtils) {
        return new ConsumerFactory(redisUtils, redisMqUtils);
    }

}
